package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealDishService;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName: SetmealController
 * Package: IntelliJ IDEA
 *
 * @author 张文豪
 * @description
 * @date 2023/8/17 18:10
 */
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Slf4j
@Api("c端-套餐浏览接口")
public class SetmealController {
    @Autowired
    private DishService dishService;
    @Autowired
    private SetmealDishService setmealDishService;
    @Autowired
    private SetmealService setmealService;
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询相关的菜品")

    public Result<List<DishItemVO>> selectBySetmeadId(@PathVariable Long id){
        log.info("查询菜品时获取到的套餐id：{}",id);
        //根据setmealid返回dishid
        List<Long> list = setmealDishService.selectIdBySetmealId(id);
        List<DishItemVO> newlist = dishService.selectByIds(list);
        return Result.success(newlist);
    }
    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> selectByCategoryId(Long categoryId){
        log.info("获取到的分类id：{}",categoryId);
        List<Setmeal> list = setmealService.selectByCategory(categoryId);
        return Result.success(list);
    }
}
